using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls; 
using System.Collections.Generic;
using System.Collections;
using System.Data.SqlClient;


public class DBCliente : DALBase
{
    public static void addClienteBean(ClienteBean beanParametro)
    {
        using (SqlConnection conn = new SqlConnection(prCadConexion))
        {
            using (SqlCommand cmd = new SqlCommand("USPW_CLIENTE_I", conn))
            {
                conn.Open();
                cmd.CommandTimeout = 0;
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@CODIGO", fnVerNuloStr(beanParametro.codigo)));

                cmd.Parameters.Add(new SqlParameter("@NOMBRE", fnVerNuloStr(beanParametro.nombre)));

                cmd.Parameters.Add(new SqlParameter("@DIRECCION", fnVerNuloStr(beanParametro.direccion)));
                
                cmd.Parameters.Add(new SqlParameter("@FLAG", fnVerNuloStr(beanParametro.flag)));

                cmd.Parameters.Add(new SqlParameter("@ID", fnVerNuloStr(beanParametro.id)));

                cmd.Parameters.Add(new SqlParameter("@LATITUD", fnVerNuloStr(beanParametro.latitud)));

                cmd.Parameters.Add(new SqlParameter("@LONGITUD", fnVerNuloStr(beanParametro.longitud)));

                cmd.ExecuteNonQuery();

            }
        }
    }

    public static ClienteBean getClienteBeanPK(String id)
    {
        ClienteBean bean = null;
        using (SqlConnection conn = new SqlConnection(prCadConexion))
        {
            using (SqlCommand cmd = new SqlCommand("USPW_CLIENTE_S_PK", conn))
            {
                conn.Open();
                cmd.CommandTimeout = 0;
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@ID", id));

                using (SqlDataReader loDr = cmd.ExecuteReader())
                {
                    while (loDr.Read())
                    {
                        bean = new ClienteBean();
                        bean.codigo = loDr.GetValue(loDr.GetOrdinal("CODIGO")).ToString().Trim();

                        bean.nombre = loDr.GetValue(loDr.GetOrdinal("NOMBRE")).ToString().Trim();

                        bean.direccion = loDr.GetValue(loDr.GetOrdinal("DIRECCION")).ToString().Trim();

                        bean.flag = loDr.GetValue(loDr.GetOrdinal("FLAG")).ToString().Trim();

                        bean.id = loDr.GetValue(loDr.GetOrdinal("ID")).ToString().Trim();

                        bean.latitud = loDr.GetValue(loDr.GetOrdinal("LATITUD")).ToString().Trim();

                        bean.longitud = loDr.GetValue(loDr.GetOrdinal("LONGITUD")).ToString().Trim();

                    }
                }
            }
        }

        return bean;
    }

    public static List<AbstractBean> findClienteBean(ClienteBean beanParametro)
    {
        List<AbstractBean> lista = new List<AbstractBean>();
        ClienteBean bean = null;


        /**********************************************************************/
        using (SqlConnection conn = new SqlConnection(prCadConexion))
        {

            using (SqlCommand cmd = new SqlCommand("USPW_CLIENTE_S_BUSQUEDA", conn))
            {
                conn.Open();
                cmd.CommandTimeout = 0;
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@CODIGO", fnVerNuloStr(beanParametro.codigo)));

                cmd.Parameters.Add(new SqlParameter("@NOMBRE", fnVerNuloStr(beanParametro.nombre)));
                
                cmd.Parameters.Add(new SqlParameter("@DIRECCION", fnVerNuloStr(beanParametro.direccion)));

                cmd.Parameters.Add(new SqlParameter("@FLAG", fnVerNuloStr(beanParametro.flag)));

                cmd.Parameters.Add(new SqlParameter("@PIV_PAG_ACTUAL", beanParametro.paginaactual));

                cmd.Parameters.Add(new SqlParameter("@PIV_NUMERO_REGISTROS", beanParametro.registroporpagina));

                cmd.Parameters.Add(new SqlParameter("@BUSCARNAME", fnVerNuloStr(beanParametro.buscarname)));

                cmd.Parameters.Add(new SqlParameter("@BUSCARORDEN", beanParametro.buscarorden));


                using (SqlDataReader loDr = cmd.ExecuteReader())
                {
                    while (loDr.Read())
                    {
                        bean = new ClienteBean();
                        bean.codigo = loDr.GetValue(loDr.GetOrdinal("CODIGO")).ToString().Trim();

                        bean.nombre = loDr.GetValue(loDr.GetOrdinal("NOMBRE")).ToString().Trim();

                        bean.direccion = loDr.GetValue(loDr.GetOrdinal("DIRECCION")).ToString().Trim();

                        bean.flag = loDr.GetValue(loDr.GetOrdinal("FLAG")).ToString().Trim();

                        bean.id = loDr.GetValue(loDr.GetOrdinal("ID")).ToString().Trim();

                        bean.tamaniototal = loDr.GetValue(loDr.GetOrdinal("TAMANIOTOTAL")).ToString().Trim();
                        lista.Add(bean);
                    }
                }
            }
        }

        return lista;
    }

}